import { HTTP } from "../../../utils/http"
import api from '../../../utils/api.js'
import { config } from '../../../utils/config'
let http = new HTTP()
Page({
    data: {
        date: '2020-09',
        year: 2020,
        month: '06',
        entTime:'',
        itemimg: config.imgUrl + '/images/my/s6.png',
        imgUrl: config.imgUrl,
    },
    bindDateChange: function(e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        let timeDay = e.detail.value;
        let [year, month] = timeDay.split('-')
        this.setData({
            year,
            month
        })
        let user_token = wx.getStorageSync('token')
        this.queryJifen(user_token, timeDay)
    },
    onShow: function() {
        var timestamp = Date.parse(new Date());
        timestamp = timestamp / 1000;
        var n = timestamp * 1000;
        var date = new Date(n);
        let user_token = wx.getStorageSync('token')
        let y = date.getFullYear();
        let m = date.getMonth() + 1;

        function addPrefixZero(m) {
            for (var i = 0; i < m; i++) {
                var k = i * i + 1;
                if (k < 10) {
                    return "0" + m;
                } else {
                    return m;
                }
            }

        }
        let timeDay = y + '-' + addPrefixZero(m)
        console.log(timeDay)
        this.setData({entTime: timeDay})
        this.queryJifen(user_token, timeDay, y, m)

    },
    queryJifen(user_token, timeDay, y, m) {
        http.request({
            url: api.getFrozenCash,
            data: {
                token: user_token,
                month: timeDay
            },
            success: (res) => {
                console.log(res.data.list)
                
                this.setData({
                    list: res.data.list,
                    year: y,
                    month: m,
                    date: timeDay
                })
            }
        })
    },
    toDisable(){
        wx.navigateTo({
            url : '/pages/getJiFen/disable/disable'
        })
     },

    //获取积分
    getCoins(user_token) {
        console.log('11222333')
        http.request({
            url: api.accountCoins,
            data: {
                token: user_token
            },
            success: (res) => {
                console.log(res)
                if (res.code == 200) {
                    this.setData({
                        jifen_num: res.data.points,
                        frozen_points : res.data.frozen_points
                    })
                }
            }
        })
    }
})